<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <title>{$siteTitle}</title>
        <meta name="keywords" content="" />
        <meta name="description" content="" />
         <link rel="stylesheet" href="__PUBLIC__/admin/wx/css/default.css">
          <link href="__PUBLIC__/admin/css/style.css" rel="stylesheet" type="text/css" />
        <script type="text/javascript" src="__PUBLIC__/admin/wx/js/jquery-1.6.4.min.js"></script>
        <style>
			.place{height:40px; background:url(__PUBLIC__/admin/images/righttop.gif) repeat-x;}
			.place span{line-height:40px; font-weight:bold;float:left; margin-left:12px;}
			.placeul li{float:left; line-height:40px; padding-left:7px; padding-right:12px; background:url(__PUBLIC__/admin/images/rlist.gif) no-repeat right;}
			.placeul li:last-child{background:none;}
		</style>
    </head>
    <body>
    	<div class="place">
		    <span>位置：</span>
		    <ul class="placeul">
		    <li>首页</li>
		    <li>消息回复管理</li>
		    </ul>
		</div>
		
        <div class="col_main">
            <div class="content_wrap">
                <div class="btn_wrp">
                    <a href="javascript:void(0);" class="btn btn_add btn_primary" id="Js_rule_add" data-status="not"><i class="icon14_common add_white"></i>添加关键词</a>
                </div>
                <ul class="keywords_rule_list">
                	<!-- 新增关键词开始 start -->
                    <li class="keywords_rule_item" style="display:none;" id="keywords_item0">
                    	<form action="{:U('addKeyword')}" method="post" onsubmit="return checkSubmitKeyword();">
                    		<input name="reply_type" type="hidden" value="0" id="reply_type"/>
	                        <div class="keywords_rule_hd no_extra Js_detail_switch" data-id="200322276" data-reply="empty" style="-webkit-transition: all, 1s;">
	                            <div class="info">
	                                <em class="keywords_rule_num">新关键字</em>
	                                <strong class="keywords_rule_name"></strong>
	                            </div>
	                        </div>
	                        <div class="keywords_rule_bd keywords_rule_detail">
	                            <div class="rule_name_area">
	                                <div class="frm_control_group">
	                                    <label for="" class="frm_label">关键字</label>
	                                    <div class="frm_controls">
	                                        <span class="frm_input_box"><input type="text" class="frm_input" id="news_key" name="news_key" value=""></span>
	                                        <p class="frm_tips">关键字最多10个汉字</p>
	                                    </div>
	                                </div>
	                            </div>
	                            <div class="keywords_tap reply">
	                                <div class="keywords_tap_hd">
	                                    <div class="info">
	                                        <h4>回复</h4>
	                                    </div>
	                                </div>
	                                <div class="keywords_tap_bd">
	                                    <ul class="media_type_list">
	                                        <li class="tab_text" data-tooltip="文字"><a href="javascript:;" data-type="1" data-id="200322276" class="Js_reply_add Js_reply_add_text">&nbsp;<i class="icon_msg_sender"></i></a></li>
	                                        <li class="tab_appmsg" data-tooltip="图文"><a href="javascript:;" data-type="5" data-id="200322276" class="Js_reply_add Js_reply_add_photo">&nbsp;<i class="icon_msg_sender"></i></a></li>
	                                    </ul>
	                                    <ul class="keywords_list" id="">
	                                    	<input type="hidden" name="reply_detail" id="reply_detail_input"/>
	                                    	<li style="z-index: 0; display: none;" id="keyword_span_li">
	                                            <div class="desc">
	                                                <div class="media_content Js_media_content" id="Js_mediaContent_200322276_0" data-index="0" data-type="1"></div>
	                                            </div>
	                                            <div class="opr">
	                                                <a href="javascript:;" class="icon14_common edit_gray Js_reply_edit">编辑</a>
	                                            </div>
                                        	</li>
	                                    </ul>
	                                </div>
	                            </div>
	                        </div>
	                        <div class="keywords_rule_ft">
	                            <p class="media_stat info">文字(<em data-type="1" class="num Js_reply_cnt" id="add_text_num">0</em>)、                图文(<em data-type="5" class="num Js_reply_cnt" id="add_tuwen_num">0</em>)</p>
	                            <div class="opr">
	                                <input type="submit" data-id="200322276" class="btn btn_primary Js_rule_save" value="保存" />
	                            </div>
	                        </div>
                        </form>
                    </li>
                    <!-- 新增关键词开始 end -->
                    
                    <foreach name="all_keyword" item="one_key">
                    <li class="keywords_rule_item" id="{$one_key.id}">
                        <div class="keywords_rule_hd no_extra Js_detail_switch" data-id="{$one_key.id}" data-reply="empty" style="-webkit-transition: all, 1s;">
                            <div class="info">
                                <em class="keywords_rule_num">关键词{$one_key.id}:</em>
                                <strong class="keywords_rule_name">{$one_key.keywords_text}</strong>
                            </div>
                            <div class="opr">
                                <a href="javascript:void(0);" class="icon_dropdown_switch highlight">展开</a>
                            </div>
                        </div>
                        <div class="keywords_rule_bd keywords_rule_overview">
                            <div class="keywords_info reply">
                                <strong class="keywords_info_title">回复</strong>
                                <div class="keywords_info_detail">
                                    <p class="reply_info">
                                    <em class="num">1</em>条（ <em data-type="1" class="num Js_reply_cnt2"><if condition="$one_key.reply_type eq 0">1<else />0</if></em>条文字，<em data-type="5" class="num Js_reply_cnt2"><if condition="$one_key.reply_type eq 1">1<else />0</if></em>条图文）</p>
                                </div>
                            </div>
                        </div>
                        <div class="keywords_rule_bd keywords_rule_detail">
                            <div class="rule_name_area">
                                <div class="frm_control_group">
                                    <label for="" class="frm_label">关键字</label>
                                    <div class="frm_controls">
                                        <span class="frm_input_box"><input type="text" class="frm_input" id="keyword_text_{$one_key.id}" value="{$one_key.keywords_text}"></span>
                                        <p class="frm_tips">关键字最多22个字</p>
                                    </div>
                                </div>
                            </div>
                            <div class="keywords_tap reply">
                                <div class="keywords_tap_hd">
                                    <div class="info">
                                        <h4>回复</h4>
                                    </div>
                                </div>
                                <div class="keywords_tap_bd">
                                    <ul class="keywords_list" id="">
                                        <li style="z-index: 0">
                                            <div class="desc">
                                            	<input type="hidden" name="keyword_detail" id="keyword_detail_{$one_key.id}" value="{$one_key.reply_detail}"/>
                                                <div class="media_content Js_media_content" id="Js_mediaContent_{$one_key.id}" data-index="0" data-type="1">{$one_key.reply_detail}</div>
                                            </div>
                                            <div class="opr">
                                                <a href="javascript:;" onclick="editKeyword({$one_key.id},{$one_key.reply_type})" class="icon14_common edit_gray  Js_reply_edit">编辑</a>
                                                <!-- <a href="javascript:;" data-id="{$one_key.id}" class="icon14_common del_gray Js_reply_del">删除</a> -->
                                            </div>
                                        </li>
                                    </ul>
                                </div>
                            </div>
                        </div>
                        <div class="keywords_rule_ft">
                            <p class="media_stat info">文字(<em data-type="1" class="num Js_reply_cnt"><if condition="$one_key.reply_type eq '0'">1<else />0</if></em>)、图文(<em data-type="5" class="num Js_reply_cnt"><if condition="$one_key.reply_type eq '1'">1<else />0</if></em>)</p>
                            <div class="opr">
                            	<a href="javascript:;" onclick="updateKeyword({$one_key.id},{$one_key.reply_type})" data-id="{$one_key.id}" class="btn btn_primary Js_rule_save">保存</a>
                                <a href="javascript:void(0);" data-id="{$one_key.id}" onclick="deleteKeyword('{$one_key.id}','{$one_key.keywords_text}')" class="btn btn_default Js_rule_del">删除</a>
                            </div>
                        </div>
                    </li>
                    </foreach>
                </ul>
            </div>
            <div class="pagin" style="width: 1000px; float: left; padding-bottom: 50px; margin-left: 20px;"> 
<!-- 			    	<div class="message">共<i class="blue">{$article_total}</i>条记录，当前显示第&nbsp;<i class="blue">{$page_now}&nbsp;</i>页</div> -->
			       {$page}
 			    </div> 
			
        </div>
        
    
		
        <div class="dialog_wrap" id="dialog_text">
            <div class="dialog_bg"></div>
            <div class="dialog">
                <div class="dialog_hd">
                    <h3>填写回复文字</h3>
                    <a href="javascript:;" onclick="return false" class="icon16_opr closed pop_closed">关闭</a>
                </div>
                <div class="dialog_bd">
                    <div class="emotion_editor_wrp" id="Js_textEditor">
                        <div class="emotion_editor">
                            <div class="edit_area js_editorArea" style="display: none;"></div>
                            <div class="edit_area js_editorArea" id="keyword_detail_area" contenteditable="true" style="overflow-y: auto; overflow-x: hidden;"></div>
                            <div class="editor_toolbar">
                                <p style="float: left; color:red;">注：如果要推送超链接，添加&lt;a href='&nbsp;&nbsp;'&gt;XXX&lt;/a&gt;，引号一定要用英文单引号。</p><p class="editor_tip js_editorTip">最多可以输入<em>250</em>个汉字</p>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="dialog_ft">
                    <span class="btn btn_primary btn_input js_btn_p"><button type="button" class="js_btn" id="keyword_submit" data-index="0">确定</button></span>
                    <span class="btn btn_default btn_input js_btn_p"><button type="button" class="js_btn cancel_dialog" data-index="1">取消</button></span>
                </div>
            </div>
        </div>
        <div class="dialog_wrap" id="dialog_photo">
            <div class="dialog_bg"></div>
            <div class="dialog" style="margin-top:-195.5px; width: 600px; margin-left: -300px;">
                <div class="dialog_hd">
                    <h3>填写图文素材KEY值</h3>
                    <a href="javascript:;" onclick="return false" class="icon16_opr closed pop_closed">关闭</a>
                </div>
                <div class="dialog_bd">
                    <div style="position: relative; height: 100px;">
                        <div class="no_media_wrp">
                            <div class="appmsg_edit_item">
                                    <label for="" class="frm_label" style="width: 6em; font-weight: bolder;font-size: 14px;">图文key值:</label>
                                    <span class="frm_input_box"><input type="text" class="frm_input js_title" name="news_title" id="keyword_tuwen_key" value=""/></span>
                            </div>
                        </div>
                        <span class="vm_box"></span>
                    </div>
                </div>
                <div class="dialog_ft">
                    <span class="btn btn_primary btn_input js_btn_p"><button type="button" id="keywords_tuwen" class="js_btn" data-index="0">确定</button></span>
                    <span class="btn btn_default btn_input js_btn_p"><button type="button" class="js_btn cancel_dialog" data-index="1">取消</button></span>
                </div>
            </div>
        </div>
        <script type="text/javascript">
	        var jmz = {};
	        var key_id = 0;
	        jmz.GetLength = function(str) {
	            ///<summary>获得字符串实际长度，中文2，英文1</summary>
	            ///<param name="str">要获得长度的字符串</param>
	            var realLength = 0, len = str.length, charCode = -1;
	            for (var i = 0; i < len; i++) {
	                charCode = str.charCodeAt(i);
	                if (charCode >= 0 && charCode <= 128) realLength += 1;
	                else realLength += 2;
	            }
	            return realLength;
	        };
	        function checkSubmitKeyword() {
	        	var news_key = $("#news_key").val();
	        	var reply_detail_input = $("#reply_detail_input").val();
	        	if(news_key == "") {
	        		alert("关键字不能为空！");
	        		return false;
	        	} else {
	        		var news_key_length = jmz.GetLength(news_key);
	        		if(news_key_length > 20) {
	        			alert("关键字不能超过10个汉字或20个字符！");
		        		return false;
	        		} 
	        	}
	        	if(reply_detail_input == "") {
	        		alert("关键字回复不能为空！");
	        		return false;
	        	}
	        }
	        //更新关键字
	        function updateKeyword(keywordId, key_type) {
	        	//alert("key_id="+key_id+"type="+key_type);
	        	var key_text = $("#keyword_text_"+keywordId).val();
	        	var key_detail = $("#keyword_detail_"+keywordId).val();
	        	$.post("{:U('ajaxUpdateKeyword')}",
	        			{id:keywordId,keywords_text:key_text,reply_detail:key_detail},
	        			function(msg){
		    				if(msg==1){
		    					alert("更新“"+key_text+"”关键字成功！");
		    				}else{
		    					alert(msg);
		    				}
    			});
	        }
	        
	        function deleteKeyword(onekeyId,onekeyword) {
	        	if(confirm("您确定要删除“"+onekeyword+"”关键字吗？")) {
	        		var url = "{:U('ajaxDeleteKeyword')}";
	        		var url = url + "?id="+onekeyId;
	        		//alert(url);
	        		$.ajax({
		                type:"GET",
		                url: url,
		                dataType: 'json',           //注意这里面的格式形式！
		                success:function(data){
		               		$("#"+onekeyId).slideUp("slow");
		                }
		            });
	        	}
	        }
	        //编辑更新关键字
	        function editKeyword(keyId, key_type) {
	        	key_id = keyId;
	        	var keyword_detail = $("#keyword_detail_"+key_id).val();
	        	if(key_type == 0) {
	        		$("#keyword_detail_area").text(keyword_detail);
	        		$("#dialog_text").show();
	        	} else {
	        		$("#keyword_tuwen_key").val(keyword_detail);
	        		$("#dialog_photo").show();
	        	}
	        }
            $(function(){
                $(".keywords_rule_hd").bind("click",function(){
                    $(this).parent(".keywords_rule_item").toggleClass("open");
                });
                $("#Js_rule_add").bind("click",function(){
                    $("#keywords_item0").toggle().addClass("open");
                });
                $(".Js_reply_add_text").bind("click",function(){
                	key_id = 0;
                	$("#keyword_detail_area").text("");
                    $("#dialog_text").show();
                });
                $(".Js_reply_add_photo").bind("click",function(){
                	key_id = 0;
                	$("#keyword_detail_area").text("");
                    $("#dialog_photo").show();
                });
                $(".pop_closed,.cancel_dialog").bind("click",function(){
                    $(this).parents(".dialog_wrap").hide();
                });
                $("#keyword_submit").bind("click", function(){
                	var keywords = $("#keyword_detail_area").text();
                	var keywords_length = jmz.GetLength(keywords);
                	if(keywords_length > 500) {
                		alert("您填写的回复文字过长，不能超过250个字！");
                	} else {
                		if(key_id != 0) {
                			$("#dialog_text").hide();
                			$("#Js_mediaContent_"+key_id).text(keywords);
                			$("#keyword_detail_"+key_id).val(keywords);
                		} else {
                			$("#dialog_text").hide();
                        	$("#Js_mediaContent_200322276_0").text(keywords);
                        	$("#reply_detail_input").val(keywords);
                        	$("#reply_type").val("0");
                        	$("#add_tuwen_num").text("0");
                        	$("#add_text_num").text("1");
                        	$("#keyword_span_li").show();
                		}
                	}
                });
                $("#keywords_tuwen").bind("click", function(){
                	var keywords = trimStr($("#keyword_tuwen_key").val());
                	var key_start = keywords.substring(0,4);
                	if(key_start != "key_") {
                		alert("您填写的图文素材的key值不是以“key_”开头！请去图文素材中核对！");
                	}else if(keywords.length != 14) {
                		alert("您填写的图文素材key值的长度不对，标准为14位的字串！请去图文素材中核对！");
                	}else {
                    	if(key_id != 0) {
                			$("#dialog_text").hide();
                			$("#Js_mediaContent_"+key_id).text(keywords);
                			$("#keyword_detail_"+key_id).val(keywords);
                		} else {
                			$("#dialog_photo").hide();
                        	$("#Js_mediaContent_200322276_0").text(keywords);
                        	$("#reply_detail_input").val(keywords);
                        	$("#reply_type").val("1");
                        	$("#add_tuwen_num").text("1");
                        	$("#add_text_num").text("0");
                        	$("#keyword_span_li").show();
                		}
                	}
                });
            });
            function trimStr(str){return str.replace(/(^\s*)|(\s*$)/g,"");}
        </script>
    </body>
</html>